﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcmyjobs.Web.adverts
{
    public partial class Add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["adminName"] != null)
            {

            }
            else
            {
                Maticsoft.Common.MessageBox.ResponseScript(this, "alert('请先登陆！');top.location.href='../adminlogin2.aspx'");
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            if (this.fudSc.HasFile)//检查是否有文件
            {
                string fullFileName = this.fudSc.PostedFile.FileName;                           //文件路径名
                string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);   //图片名称
                string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1);        //图片格式

                if (type == "jpg" || type == "JPG" || type == "gif" || type == "GIF" || type == "BMP" || type == "bmp") //判断是否为图片类型
                {
                    if (this.fudSc.PostedFile.ContentLength > 500 * 1024)
                    {
                        Maticsoft.Common.MessageBox.Show(this, "上传图片必须小于500k！");
                    }
                    else
                    {
                        int locationid = int.Parse(this.ddllocation.SelectedValue.ToString());
                        string pics = HttpContext.Current.Request.MapPath("~/advpics/" + locationid.ToString() + "." + type);//获取上传文件的网站目录路径
                        this.fudSc.SaveAs(pics);//存储文件到磁盘                        
                        string alink = this.txtalink.Text;

                        lcmyjobs.Model.adverts model = new lcmyjobs.Model.adverts();
                        model.pics = "/advpics/" + locationid.ToString() + "." + type;
                        model.alink = alink;
                        model.locationid = locationid;
                        model.companyname = txtName.Text;

                        lcmyjobs.BLL.adverts bll = new lcmyjobs.BLL.adverts();
                        bll.Add(model);
                        Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "List.aspx");

                    }

                }
                else
                {
                    Maticsoft.Common.MessageBox.Show(this, "非图片类型，不允许上传！");
                }
            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "必须指定文件！");
            }

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
